package com.pxst.scheduled;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pxst.annotations.EarlyWarn;
import com.pxst.resp.ApiResp;
import com.pxst.resp.PageResp;
import com.pxst.sys.entity.UserEntity;
import com.pxst.sys.service.UserService;

import lombok.extern.slf4j.Slf4j;

/** 
 * 定时器demo
* @author yangxy
* @version 创建时间：2023年9月1日 上午10:12:38 
*/
@Slf4j
@Component
public class DemoScheduled {
	@Autowired
	private UserService userService;
	
	@Transactional
	@SuppressWarnings("unchecked")
	@EarlyWarn(content = "示例定时器")
	public void test() {
		//不分页查询示例
		List<UserEntity> list = userService.list(new QueryWrapper<UserEntity>().lambda().eq(UserEntity::getIsAdmin, 1));
		log.info("不分页示例结果集:{}",JSON.toJSONString(list));
		
		//分页查询示例
		PageHelper.startPage(1, 1);
		Page<UserEntity> page = (Page<UserEntity>) userService.list(new QueryWrapper<UserEntity>().lambda().eq(UserEntity::getIsAdmin, 0));
		//将分页转换为系统统一返回结构
		ApiResp<PageResp<UserEntity>> apiResp = ApiResp.page(page);
		log.info("分页示例结果集:{}",JSON.toJSONString(apiResp));
		
	}
}
